package dbs

import (
	"net/http"

	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql"

	"github.com/jmoiron/sqlx"
)

const (
	DB_TYPE     = "mysql"
	DB_USER     = "root"
	DB_PASSWORD = "root123456"
	DB_NAME     = "punc"
	DB_URL      = "127.0.0.1:3306"
)

func Conn(c *gin.Context) (*sqlx.DB, error) {
	database, err := sqlx.Open(DB_TYPE, DB_USER+":"+DB_PASSWORD+"@tcp("+DB_URL+")/"+DB_NAME)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 20002,
			"msg":  err.Error(),
		})
	}
	return database, err
}
